replace unbounded retry loops with bounded exponential backoff in Turtle and Block cache methods #5855
Open
Ashutoshx7 wants to merge 1 commit intosugarlabs:masterfrom
Open
Conversation
Contributor
|
✅ All Jest tests passed! This PR is ready to merge. |
ab7fa63 to
7bec4d3
Compare
Contributor
|
✅ All Jest tests passed! This PR is ready to merge. |
7bec4d3 to
b4bfb30
Compare
Contributor
|
✅ All Jest tests passed! This PR is ready to merge. |
b4bfb30 to
44deb4c
Compare
Contributor
|
✅ All Jest tests passed! This PR is ready to merge. |
shashank03-dev
suggested changes
Feb 22, 2026
shashank03-dev
left a comment
There was a problem hiding this comment.
In retryWithBackoff.js, since you’re already using await, you could simplify the logic by replacing the new Promise wrapper and recursion with a standard await for-loop. It would shorten the code and it would look a bit modern too.
…n Turtle and Block cache methods
- Extract shared retryWithBackoff utility (js/utils/retryWithBackoff.js)
- Fix Turtle._createCache: unbounded setTimeout retry -> bounded (max 20 retries)
- Fix Turtle.updateCache: unbounded async recursion with broken promise chain -> bounded retry
- Fix Turtle.updateCache: incorrect log message ('Block container' -> 'Turtle container')
- Refactor Block._createCache and Block.updateCache to use shared utility
- Register retryWithBackoff in RequireJS loader config (loader.js, activity.js)
- Add 19 unit tests for retryWithBackoff utility
44deb4c to
6457434
Compare
Contributor
|
✅ All Jest tests passed! This PR is ready to merge. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes critical unbounded retry loops in
Turtle._createCache()andTurtle.updateCache()that can cause infinite loops and browser hangs when canvas container bounds are never available. It also consolidates duplicated retry logic acrossturtle.jsandblock.jsinto a shared, well-tested utility.Problems Fixed
1. Unbounded retry in
Turtle._createCache()(infinite loop)The original code called
setTimeout(() => this._createCache(), 200)with no maximum retry limit. Ifcontainer.getBounds()never returns a value (e.g., due to a rendering failure or detached container), this loops forever, consuming memory and CPU.2. Broken promise chain in
Turtle.updateCache()(silent failures + infinite recursion)this.updateCache()call was neitherawaited norreturned, so failures were silently swallowedboundsstaysnull"Block container"instead of"Turtle container"(copy-paste bug)3. Code duplication across
turtle.jsandblock.jsThree separate hand-rolled retry implementations existed with inconsistent patterns.
block.jsalready had bounded retries with exponential backoff, butturtle.jsdid not.Changes
Before / After
Turtle._createCache()— BeforeTurtle._createCache()— After